/**
 * yry
 * 2017-02-20
 */
(function () {
	var serverData = {};
    var	serverTable;
    
    //查询1
    jQuery('#search_btn').on('click', function() {
    	serverData.beginPaidDate = jQuery('#beginPaidDate').val();
        serverData.endPaidDate = jQuery('#endPaidDate').val();
        serverData.type = jQuery('#type').val();
		serverTable.draw();
	});
	
    
    jQuery(document).ready(function () {
    	//动态加载时间
    	var date=new Date();
        var currentMonth=date.getMonth();
        var nextMonth=++currentMonth;
        var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
        if(date.getMonth()+1<10){
        	var month = "0"+(date.getMonth()+1);
        }
        if(nextMonthFirstDay.getMonth()+1<10){
        	var nextmonth = "0"+(nextMonthFirstDay.getMonth()+1);
        }
        document.getElementById("FirstYear").innerText = date.getFullYear() + "年合同到款";
        document.getElementById("SecondYear").innerText = date.getFullYear()-1 + "年合同到款";
        document.getElementById("ThreeYear").innerText = date.getFullYear()-2 + "年合同到款";
        document.getElementById("FourYear").innerText = date.getFullYear()-3 + "年合同到款";
        document.getElementById("FiveYear").innerText = date.getFullYear()-4 + "年前合同(含"+(date.getFullYear()-4)+"年)到款";
        
        document.getElementById("beginPaidDate").value=date.getFullYear()+"-"+month+"-01";//当月第一天
        document.getElementById("endPaidDate").value=nextMonthFirstDay.getFullYear()+"-"+nextmonth+"-01";//后一个月第一天
        serverData.beginPaidDate = jQuery('#beginPaidDate').val();
        serverData.endPaidDate = jQuery('#endPaidDate').val();
        serverData.type = jQuery('#type').val();
        serverTable = jQuery('#dataTable').DataTable({
        	"serverSide": true,
        	"ordering": false,
        	"pageLength" : -1,
        	"ajax": {
        		"dataType": "json",
        		"type": "get",
        		"cache": false,
        		"url":window.rootPath+ '/ui/paidMainframeStaff/getMyTrance',
        		"data": function (d) {
        			return $.extend({}, d, serverData);
        		}
        	},
            "columns" : [{
			            	data : null,
			                defaultContent : ""// 排序   1
			            },
                        {
       		        	 	data: 'sAreaName'
        	            },
        	            {
        	                data: 'name'
        	            },
        	            {
        	                data: 'nFirstYearSum'
        	                
        	            },
        	            {
        	                data: 'nSecondYearSum'
        	                
        	            },
        	            {
       		        	 	data: 'nThreeYearSum'
        	            },
        	            {
                            data: 'nFourYearSum',
                        },
        	            {
        	                data: 'nFiveYearSum'
        	            },
        	            {
        	                data: 'nTotalYearSum'
        	                
        	            },
        	            {
        	            	data: 'nDXM'
        	            		
        	            },
        	            {
        	            	data: 'nKY'
        	            		
        	            },
        	            {
        	            	data: 'nOtherTotal'
        	            		
        	            }],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
    });
})();

